package com.caigou.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jiliang.purchase.demo.CriteriaYongHulieBiao;
import jiliang.purchase.demo.YongHuliebiao;
import sch.jl.caigou.utils.Page;

import com.caigou.service.YongHuliebiaoService;

public class YongHuliebiaoServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	
	private YongHuliebiaoService YHS = new YongHuliebiaoService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		String xingming = null;
		String dw_id = null;
		String js_id = null;
		int pageNum = 1;		
		String returnTitle = "";
		
		if(request.getParameter("pageNum") != null && !request.getParameter("pageNum").equals(""))
		{
			pageNum = Integer.valueOf(request.getParameter("pageNum"));
		}
		
		if(request.getParameter("xingming")!=null && !request.getParameter("xingming").equals(""))
		{
			xingming = request.getParameter("xingming");
			returnTitle+=xingming+"|";
		}
		else
		{
			returnTitle+="a"+"|";
		}
		
		if(request.getParameter("dwid")!=null && !request.getParameter("dwid").equals("0"))
		{
			dw_id = request.getParameter("dwid");
			returnTitle+=dw_id+"|";
		}
		else
		{
			returnTitle+="b"+"|";
		}
		
		if(request.getParameter("jsid")!=null && !request.getParameter("jsid").equals("0"))
		{
			js_id = request.getParameter("jsid");
			returnTitle+=js_id+"|";
		}
		else
		{
			returnTitle+="c";
		}
		//System.out.println(returnTitle);
		CriteriaYongHulieBiao CYH = new CriteriaYongHulieBiao(xingming,dw_id,js_id,pageNum);
		
		Page<YongHuliebiao> page = new Page<YongHuliebiao>();
		page = YHS.getPage(CYH);
		
		request.setAttribute("page",page);
		request.setAttribute("returnTitle", returnTitle);
		
		request.getRequestDispatcher("leibiao.jsp").forward(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
